package com.xwdeshj.controller;

import com.alibaba.fastjson.JSONObject;
import com.xwdeshj.service.XwBusinessInfoService;
import com.xwdeshj.tasks.AsynTask;
import com.xwdeshj.utils.IMoocExceptionHandler;
import com.xwdeshj.utils.helper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by BKWJA on 2018/12/22.
 * 商家信息/主管审核表控制层
 */
@Slf4j
@RequestMapping("businesinfo")
@CrossOrigin(allowCredentials = "true")
@Controller
public class XwBusinessInfoController extends IMoocExceptionHandler {

    @Autowired
    private XwBusinessInfoService xwBusinessInfoService;

    /**
     *  升级为农家乐商家
     * @param tab 1:农家乐，2：景区
     * @param user_encryptId 商家加密id（原用户的加密id）
     * @param business_Legal 法定代表人
     * @param business_Credit 统一社会信用码
     * @param business_license 营业执照
     * @param business_tel 联系方式
     * @param business_create 成立日期
     * @param business_type 商户类型
     * @param farm_tour_type 农家类型
     * @param Business_area 经营面积
     * @param dining_reception 用餐接待容纳
     * @param room 住宿容纳
     * @param scale 商铺规模
     * @param consume 人均消费
     * @param city  城市
     * @param district 区县
     * @param address 住所
//     * @param reviewstatus 审核状态 ,默认为0
     * @param intr_info 农家乐介绍
     * @param bus_route 公交路线
     * @param Self_route 自驾路线
     * @param Remarks 备注
     * @param CompanyName 企业名称
     * @param tradestatus 营业状态
//     * @param applicant_checkencryptId 申请人加密id
     * @param Type_encryptId 农家类型加密id
     * @return
     */
    @RequestMapping("/upgradeBusines")
    @ResponseBody
    public JSONObject upgradeBusines(String tab, String user_encryptId, String business_Legal, String business_Credit,
                                     String business_license, String business_tel, String business_create, String business_type,
                                     String farm_tour_type, String Business_area, String dining_reception, String room, String scale,
                                     String consume, String city, String district, String address, String intr_info,
                                     String bus_route, String Self_route, String Remarks, String CompanyName, Integer tradestatus,
                                     String Type_encryptId, HttpServletRequest request){
        //申请人加密id  申请人加密id
       String applicant_checkencryptId = helper.ReadCookieMap(request, "uid_encryptid").toString();

        return xwBusinessInfoService.upgradeBusines(tab,user_encryptId,business_Legal,business_Credit,business_license,
                business_tel,business_create,business_type,farm_tour_type,Business_area,dining_reception,room,scale,
                consume,city,district,address,intr_info,bus_route,Self_route,Remarks,CompanyName,tradestatus,
                applicant_checkencryptId,Type_encryptId);
    }


    /**
     *  升级为景区商家
     * @param tab 1:农家乐，2：景区
     * @param user_encryptId 商家加密id（原用户的加密id）
     * @param business_Legal 法定代表人
     * @param business_Credit 统一社会信用码
     * @param business_license 营业执照
     * @param business_tel 联系方式
     * @param business_create 成立日期
     * @param business_type 商户类型
     * @param farm_tour_type 景区类型
     * @param scenic_Ticket 门票价格
     * @param tour_kftime 开放时间
     * @param scenic_suit 适合类型（适合人群）
     * @param sceni_suit_encryptId 适合类型（适合人群）加密id
     * @param scenic_season 适合季节
     * @param city  城市
     * @param district 区县
     * @param address 住所
     * @param intr_info 农家乐介绍
     * @param bus_route 公交路线
     * @param Self_route 自驾路线
     * @param Remarks 备注
     * @param CompanyName 企业名称
     * @param scenic_grade 景区等级
//     * @param applicant_checkencryptId 申请人加密id
     * @param Type_encryptId 农家类型加密id
     * @return
     */
    @RequestMapping("/upgradeSecBusines")
    @ResponseBody
    public JSONObject upgradeSecBusines(String tab, String user_encryptId, String business_Legal, String business_Credit,
                                     String business_license, String business_tel, String business_create, String business_type,
                                     String farm_tour_type, double scenic_Ticket, String tour_kftime, String scenic_suit,
                                        String sceni_suit_encryptId, String scenic_season, String city, String district,
                                        String address, String intr_info,String bus_route, String Self_route, String Remarks,
                                        String CompanyName, String scenic_grade, String Type_encryptId, HttpServletRequest request){

        return xwBusinessInfoService.upgradeSecBusines(tab,user_encryptId,business_Legal,business_Credit,business_license,
                business_tel,business_create,business_type,farm_tour_type,scenic_Ticket,tour_kftime,scenic_suit,
                sceni_suit_encryptId,scenic_season,city,district,address,intr_info,bus_route,Self_route,Remarks,CompanyName,
                scenic_grade,Type_encryptId,request);
    }


    /**
     * 商家信息列表查询
     * @param pageindex 当前页码
     * @param pagesize 每页显示多少
     * @param starttime 开始时间
     * @param endtime 结束时间
     * @param sortfild 排序字段
     * @param sortway 排序方式
     * @param business_type 商户类型
     * @param reviewStatus 审核状态
     * @param searchval   查询关键字
     * @param searchkey  查询字段名
     * @return
     */
    @RequestMapping("/getbusinessinfolist")
    @ResponseBody
    public JSONObject getbusinessinfolist(@RequestParam(value = "pageindex",defaultValue = "1")Integer pageindex,
                                    @RequestParam(value = "pagesize",defaultValue = "10") Integer pagesize,
                                    @RequestParam(value = "starttime",defaultValue = "") String starttime,
                                    @RequestParam(value = "endtime",defaultValue = "") String endtime,
                                    @RequestParam(value = "sortfild",defaultValue = "business_createtime") String sortfild,
                                    @RequestParam(value = "sortway",defaultValue = "desc")String sortway,
                                    @RequestParam(value = "business_type",defaultValue ="" )String business_type,
                                    @RequestParam(value = "reviewStatus",defaultValue ="" )String reviewStatus,
                                    @RequestParam(value = "searchval",defaultValue = "") String searchval,
                                    @RequestParam(value = "searchkey",defaultValue = "") String searchkey,
                                          HttpServletRequest request){
        return xwBusinessInfoService.getbusinessinfolist(pageindex,pagesize,starttime,endtime,sortfild,sortway,
                business_type,reviewStatus,searchval,searchkey,request);
    }


    /**
     * 删除商家信息，删除商家基本信息后，自动删除商家的所有的记录信息
     * @param business_encryptId 商家id
     * @param farm_encryptId 农家乐店铺id
     * @param sec_encryptId 景区店铺id
     * @return
     */
    @RequestMapping("/delbusinessinfo")
    @ResponseBody
    public JSONObject delbusinessinfo(@RequestParam(value ="business_encryptId",defaultValue = "") String business_encryptId,
                                      @RequestParam(value ="farm_encryptId",defaultValue = "") String farm_encryptId,
                                      @RequestParam(value ="sec_encryptId",defaultValue = "")String sec_encryptId,
                                      HttpServletRequest request){

        if(sec_encryptId == null){
            sec_encryptId = "";
        }
        if(farm_encryptId == null){
            farm_encryptId = "";
        }
        return xwBusinessInfoService.delbusinessinfo(business_encryptId,farm_encryptId,sec_encryptId,request);
    }

    /**
     * 商家信息审核
     * @param pageindex 当前页码
     * @param pagesize 每页显示多少
     * @param starttime 开始时间
     * @param endtime 结束时间
     * @param sortfild 排序字段
     * @param sortway 排序方式
     * @param appliacnt 申请人下拉
     * @param business_type 商户类型
     * @param reviewStatus 审核状态
     * @param reviewer 审核人下拉
     * @param searchval   查询关键字
     * @param searchkey  查询字段名
     * @return
     */
    @RequestMapping("/checkbusinessinfo")
    @ResponseBody
    public JSONObject checkbusinessinfo(@RequestParam(value = "pageindex",defaultValue = "1")Integer pageindex,
                                        @RequestParam(value = "pagesize",defaultValue = "10") Integer pagesize,
                                        @RequestParam(value = "starttime",defaultValue = "") String starttime,
                                        @RequestParam(value = "endtime",defaultValue = "") String endtime,
                                        @RequestParam(value = "sortfild",defaultValue = "business_createtime") String sortfild,
                                        @RequestParam(value = "sortway",defaultValue = "desc")String sortway,
                                        @RequestParam(value = "appliacnt",defaultValue ="" )String appliacnt,
                                        @RequestParam(value = "business_type",defaultValue ="" )String business_type,
                                        @RequestParam(value = "reviewStatus",defaultValue ="" )String reviewStatus,
                                        @RequestParam(value = "reviewer",defaultValue ="" )String reviewer,
                                        @RequestParam(value = "searchval",defaultValue = "") String searchval,
                                        @RequestParam(value = "searchkey",defaultValue = "") String searchkey,
                                        HttpServletRequest request){

        return xwBusinessInfoService.checkbusinessinfo(pageindex,pagesize,starttime,endtime,sortfild,sortway,
                appliacnt,business_type,reviewStatus,reviewer,searchval,searchkey,request);
    }

    /**
     * 审核操作
     * @param business_encryptId 商家id
     * @param type 1：同意，2：拒绝
     * @param remark 备注信息
     * @param request
     * @return
     */
    @RequestMapping("/checkOperate")
    @ResponseBody
    public JSONObject checkOperate(String business_encryptId,String type,String remark,HttpServletRequest request){
        return xwBusinessInfoService.checkOperate(business_encryptId,type,remark,request);
    }

    /**
     * 撤回操作
     * @param business_encryptId 商家加密id
     * @param request
     * @return
     */
    @RequestMapping("/checkRevoke")
    @ResponseBody
    public JSONObject checkRevoke(String business_encryptId,HttpServletRequest request){
        return xwBusinessInfoService.checkRevoke(business_encryptId,request);
    }

    /**
     * 每隔7天，删除用户升级为商家，已被拒绝的数据
     * @param request
     * @return
     */
    @RequestMapping("/delbussinessRefuse")
    @ResponseBody
    public JSONObject delbussinessRefuse(HttpServletRequest request){
        return xwBusinessInfoService.delbussinessRefuse(request);
    }

}
